<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="format-detection" content="telephone=no, email=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <title>Title</title>
    <style>
        li {
            display: none;
        }

        .active {
            background: blue;
        }


    </style>
</head>
<body>

<div class="box" id="box1">
    <input type="button" value="按钮1" class="active"/>
    <input type="button" value="按钮2" />
    <input type="button" value="按钮3"/>
    <ul class="show">
        <li style="display: block;">11111</li>
        <li>22222</li>
        <li>33333</li>
    </ul>
</div>
<div class="box" id="box2">
    <input type="button" value="按钮1" class="active"/>
    <input type="button" value="按钮2" />
    <input type="button" value="按钮3"/>
    <ul class="show">
        <li style="display: block;">11111</li>
        <li>22222</li>
        <li>33333</li>
    </ul>
</div>


<script>


    function TabSwich(id) {
        var oDiv = document.querySelector(id);
        this.aBtn = oDiv.querySelectorAll("input");
        this.aDiv = oDiv.querySelectorAll("li");
        var i = 0;
        var _this = this;

        for (i = 0; i < this.aBtn.length; i++) {
            this.aBtn[i].index = i;
            this.aBtn[i].onclick = function () {
                _this.tab(this)
            }
        }
    }
    TabSwich.prototype.tab = function (oBtn) {
//       var i=0;i<this.aBtn.length;i++
        for (var i = 0; i < this.aBtn.length; i++) {
            this.aBtn[i].className = '';
            this.aDiv[i].style.display = 'none'
        }
        oBtn.className = "active";
        this.aDiv[oBtn.index].style.display = 'block'
    }

    window.onload = function () {
        var oTab1 = new TabSwich("#box1")
        var oTab2 = new TabSwich("#box2")
    }
</script>
</body>
</html>